#!/bin/bash
# Opens the OxiPhys setup window from the bundle inside this app (0.9.1.3).
HERE="$(cd "$(dirname "$0")/../Resources/bundle" && pwd)"
PY=""
for c in python3.13 python3.12 python3.11 python3.10 python3 \
         /Library/Frameworks/Python.framework/Versions/Current/bin/python3 \
         /opt/homebrew/bin/python3 /usr/local/bin/python3; do
    if command -v "$c" >/dev/null 2>&1 && "$c" -c 'import sys, tkinter
sys.exit(0 if sys.version_info >= (3, 10) and tkinter.TkVersion >= 8.6 else 1)' >/dev/null 2>&1; then
        PY="$c"
        break
    fi
done
if [ -z "$PY" ]; then
    /usr/bin/osascript -e 'display dialog "OxiPhys needs Python 3.10 or newer with Tk 8.6.\n\nInstall Python from python.org (it includes Tk), then open this installer again." with title "OxiPhys setup" buttons {"Open python.org", "Close"} default button 1' \
        -e 'if button returned of result is "Open python.org" then open location "https://www.python.org/downloads/macos/"' >/dev/null 2>&1
    exit 1
fi
cd "$HERE" || exit 1
exec "$PY" oxiphys_setup.py "$@"
